package com.weizhizs.assistant.code.template.data;

import com.weizhizs.assistant.code.config.ParamConfig;
import com.weizhizs.assistant.code.helper.BeanHelper;
import com.weizhizs.assistant.code.template.EnumDataLoador;
import com.weizhizs.assistant.code.vo.EnumVO;
import com.weizhizs.assistant.utils.DateUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class JavaEnumData implements EnumDataLoador {

    public static String getEnumName(String enumName) {
        return enumName;
    }

    public static String getFullClassName(String classPath, String enumName) {
        return classPath + "." + getEnumName(enumName);
    }

    @Override
    public String getTemplateName(EnumVO enumVO) {
        return ParamConfig.getInstance().getTemplatePath() + "/enum.java.vm";
    }

    @Override
    public String getFileName(String enumName) {
        return getEnumName(enumName) + ".java";
    }

    @Override
    public String getFileOutPath() {
        return ParamConfig.getInstance().getEnumOutPath();
    }

    @Override
    public Map<String, Object> getDataMap(EnumVO enumVO) {
        String enumName = enumVO.getParamType();

        Map<String, Object> map = new HashMap<>(16);
        map.put("enumName", enumName);
        map.put("enumTypeName", enumVO.getTypeName());
        map.put("entityOutPath", getFileOutPath());
        map.put("validatePath", ParamConfig.getInstance().getValidatePath());

        map.put("authorName", ParamConfig.getInstance().getAuthorName());
        map.put("version", ParamConfig.getInstance().getVersion());
        map.put("currentDate", DateUtils.nowDateString());

        map.put("allParams" , enumVO.getAllParam());

        map.put("entityLocalFields", Arrays.asList(ParamConfig.getInstance().getEntityLocalFields()));

        map.put("entityBaseClassName", BeanHelper.getBeanClassName(ParamConfig.getInstance().getEntityBaseClass()));
        map.put("entityBaseFullClassName", ParamConfig.getInstance().getEntityBaseClass());

        map.put("verifyFailExceptionClass", ParamConfig.getInstance().getVerifyFailExceptionClass());

        return map;
    }

}
